<template>
  <div class="alarmConfiguration zy-content">
    <search :columns="searchData" @getSearch="getSearch(arguments)"></search>
    <div class="list-layout mt16">
      <div class="btns clear">
        <span class="title">{{ $t("common.listInformation") }}</span>
        <Button @click="exportTemplateClick">{{
          $t("common.batchExport")
        }}</Button>
      </div>
      <div class="tableContent">
        <Table
          class="resizable-table"
          border
          @on-column-width-resize="onColumnWidthResize"
          :columns="columnsList"
          ellipsis
          ref="selection"
          stripe
          :data="dataArr"
          @on-selection-change="onSelectChange"
        >
          <template slot-scope="{ row }" slot="action">
            <span class="operationBtn" @click="createfaultCodeShowH(row)"
              ><i class="iconfont zy-common-bianji"></i
              >{{ $t("common.Edit") }}</span
            >
            <span class="operationBtn" @click="delPrrShowH(row)"
              ><i class="iconfont zy-common-shanchu"></i
              >{{ $t("common.Delete") }}</span
            >
          </template>
          <template slot-scope="{ row }" slot="model">
            <span class="row_click" @click="showRowDetail(row)">{{
              row.batchNumber
            }}</span>
          </template>
        </Table>
      </div>
      <!-- 分页 -->
      <div class="pageWrap mt16">
        <pageLeftTitle :total="total" :selected="delIds.length" />
        <Page
          :total="total"
          :page-size="pageSize"
          :page-size-opts="pageSizeOption"
          :current="pageNum"
          @on-change="changePageNum"
          @on-page-size-change="changePageSize"
          show-sizer
          show-total
        />
      </div>
    </div>
  </div>
</template>

<script>
import search from "@/components/curd/searchList.vue";
import fileDownload from "js-file-download";
import toggleTableOperation from "@/mixins/toggleTableOperation";
export default {
  name: "storeHouse", //仓库配置
  components: { search },
  mixins: [toggleTableOperation],
  data() {
    return {
      importExcelState: false /*批量导入*/,
      loading: false,
      create: false,
      searchParams: {},
      pageNum: 1,
      pageSize: 10,
      total: 0,

      searchData: [
        {
          title: "功能位置",
          key: "installPosition",
          type: "cascader",
          dicUrl: "/basic/organization/findListByToken?level=0",
          params: {
            label: "name",
            value: "code",
            children: "children",
          },
        },
        {
          title: "设备编号",
          key: "deviceCode",
        },
        {
          title: "转产类型",
          key: "changingType",
          type: "select",
          dicData: [
            {
              label: "换模转产",
              value: "换模转产",
            },
            {
              label: "换料转产",
              value: "换料转产",
            },
            {
              label: "产品更换转产",
              value: "产品更换转产",
            },
          ],
        },
        {
          title: "转产后工单",
          key: "workCode",
        },
        {
          title: "转产后模具名称",
          key: "moldName",
        },

        {
          title: "转产结束人",
          key: "changingEndMan",
        },
        {
          title: "转产时间",
          key: "time",
          // span:8,
          type: "daterange",
        },
      ],
      columns: [
        {
          key: "selection",
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          title: "功能位置",
          key: "installPositionName",
          minWidth: 130,
          align: "center",
          resizable: true,
        },

        {
          title: "转产类型",
          key: "changingType",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "设备编号",
          key: "deviceCode",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "转产开始时间",
          key: "changingTime",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "转产开始人",
          key: "changingMan",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "转产结束时间",
          key: "changingEndTime",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "转产时长(min)",
          key: "changingDuration",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "转产结束人",
          key: "changingEndMan",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "转产前工单",
          key: "changeWorkCode",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "转产前产品编号",
          key: "changeMaterialCode",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "转产前产品名称",
          key: "changeMaterialName",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "转产前模具编号",
          key: "changeMoldCode",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        // {
        //     //title: '操作',
        //     title: `${this.$t('common.operation')}`,
        //     slot: "action",
        //     fixed: 'right',
        //     minWidth: 160,
        //     align: "center"
        // }
        {
          title: "转产后工单",
          key: "workCode",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "转产后产品编号",
          key: "materialCode",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "转产后产品名称",
          key: "materialName",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "转产后模具编号",
          key: "moldCode",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "转产备注",
          key: "changingRemarks",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
      ],
 
      dataArr: [],
      pageSizeOption: [10, 20, 30, 40],
      delIds: [],
      selection: [],
    };
  },
  mounted() {
    this.getTableColumnsWidth(this.columns);
    this.searchList();
  },
  methods: {
    getSearch(arg){
      this.searchParams=JSON.parse(JSON.stringify(arg[0]))
      const {installPosition,time} =this.searchParams
      if (installPosition && installPosition.length!==0) {
        this.searchParams.installPosition=installPosition.at(-1)
      }else delete this.searchParams.installPosition
      if (time && time.length==2) {
        this.searchParams.endTime1=this.searchParams.time[0];
        this.searchParams.endTime2=this.searchParams.time[1];
        delete this.searchParams.time;
      }
      this.pageNum=1;
      this.searchList();
    },
    showRowDetail(row) {
      this.dataArr2 = {
        ...row,
      };
      this.showDetailDialog = true;
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },
    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    //查询列表
    searchList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        ...this.searchParams,
      };
      this.axios({
        method: "post",
        url: "/dms/productionWork/installMoldRecordPage",
        data: params,
      }).then((res) => {
        if (res.code === 200) {
          this.dataArr = res.data.records;
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    //导出
    exportTemplateClick() {
      let params = {
      };
      for (let key in this.searchParams) {
        if (this.searchParams[key]) {
          this.$set(params, key, this.searchParams[key]);
        }
      }
      const filName = "装模记录";
      this.axios({
        url:'/dms/productionWork/exportInstallMoldRecord',
        data:params,
        // responseType: "blob",
        method: "post",
      }).then((res) => {
        if (res.code==1) {
          this.$Message.warning({
            content:res.msg,  
            duration: 6,
            closable: true,
          });
        }else{
          this.axios({
            url:'/dms/productionWork/exportInstallMoldRecord',
            data:params,
            responseType: "blob",
            method: "post",
          }).then((res) => {
            fileDownload(res, filName + ".xlsx");
          });
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.ivu-input-number {
  width: -webkit-fill-available;
}

.row_click {
  cursor: pointer;
  color: rgb(50, 113, 240) !important;
}
</style>